home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10558 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: surfnet.nl!sun4nl!ittpub!ittpub!nntp
  2. Newsgroups: comp.lang.c++
  3. Subject: Re: Question: outLined inlines/ Vtab replication
  4. Message-ID: <1996Mar8.172247.1796@ittpub>
  5. From: wil@ittpub.nl (Wil Evers)
  6. Date: 8 Mar 96 17:22:47 WET
  7. References: <4hp08l$5sd@newdelph.cig.mot.com>
  8. Distribution: world
  9. Nntp-Posting-Host: lintilla
  10.  
  11. In article <4hp08l$5sd@newdelph.cig.mot.com> Martin O'Hara <oharam>  
  12. writes:
  13.  
  14. > I have a couple of questions that Im not 100 percent on
  15. > If a function is declared inline by the programmer but the address of
  16. > this function is taken in the code somewhere then the compiler will
  17. > generate a callable function. This may also happpen if the inline is
  18. > recursive or too big.
  19. > Q. Is a copy of such a function  placed in each translation unit in
  20. > which it is needed ( code duplication). Is this an "outlined inline"?
  21.  
  22. Normally, yes. Inline functions have internal linkage, even when they're  
  23. not inlined. However, I don't think a compiler would violate the standard  
  24. by not replicating the code if it were able to somehow uniquely identify a  
  25. translation unit where it can put the `outlined' inline function. See  
  26. below.  
  27.  
  28. > Q. Can there exist inline expanded code representing the function and
  29. > also a callable version of the function in different parts of a
  30. > program.? Or will the compiler decide that if all occorrences of the
  31. > function cannot be inline expanded then the function will just be a
  32. > normal one?
  33.  
  34. Yes. I would expect this to happen if the address of a simple inline  
  35. function is taken: a decent compiler will still try to inline where it  
  36. can.
  37.  
  38. > I also have a question regarding VTABs
  39. > The C++ standard states that smart compilers will look for the first non
  40. > inline virtual function definition of a class and place one copy of the
  41. > VTAB in that translation unit. 
  42.  
  43. Where in the C++ standard is this specified? I don't think the standard  
  44. requires the use of vtbls at all. vtbls are just a (commonly used) way to  
  45. implement virtual member functions. In practice, the technique you  
  46. describe is a common heuristic compilers use to determine where to put the  
  47. vtbl.
  48.  
  49. > In what cases will the VTAB be replicated (anywhere the class
  50. > h file is included) by a smart compiler. 
  51. > A. If there are no non inline virtuals?
  52. > B  If there are no non virtual functions in the class (C++ standard)?
  53.  
  54. Given the above heuristic, a decent compiler will have to replicate the  
  55. vtbl if (1) it cannot uniquely identify a translation unit where it should  
  56. put it  - this happens when a class has no non-inline virtuals - and (2)  
  57. the compiler needs an address for the vtbl - I would expect this to happen  
  58. if the translation unit contains a (possibly inlined) constructor or  
  59. destructor definition that may (indirectly) call one of the class's  
  60. virtual functions.
  61.  
  62. Regards,
  63.  
  64. - Wil
  65.  
  66.